<%@ page contentType="text/html;charset=utf-8"%>
<%@ page
	import="java.io.*, java.sql.*, java.util.*, java.text.*, napal.*, util.*, napal.*"%>
<%@ page import="org.apache.ibatis.*"%>
<%@ page import="java.util.Date"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="my" %>


<%
	request.setCharacterEncoding("utf-8");
String u = (String)session.getAttribute("userID");
String m = (String)session.getAttribute("managerID");
int currentPage = 1, pageSize = 10;
String spg = request.getParameter("pg");
if (spg != null) currentPage = Integer.parseInt(spg);

%>
<%



	
%>
<%@ include file="./Header.jsp"%>
			</td>
		</TR>
		<TR HEIGHT="100">
		<td>
		
		
		
		
		
		<form method=post action="BoardView">
		<p align="right">
		<%
if(m!=null||u!=null){ %>
<input type=button value="글쓰기" OnClick="window.location='BoardWrite.jsp'" class="btn btn-inverse">
		
		<% } %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
		<table class="table" width="100%">
		<Tr>
			<td width=5%><p align=center>번호</p></td>
			<td width=13%><p align=center>말머리</td>
		<td width=12%><p align=center>이름</p></td>
		<td width=50%><p align=center>제목</p></td>
		<td width=20%><p align=center>등록일</p></td>
		</Tr>
		<%
			if ("검색".equals(request.getParameter("cmd"))){
				String search_select = request.getParameter("search_select");
				String search_text = request.getParameter("search_text");
				if(search_text!=null){
					if(search_select.equals("제목")){
						for(Board b : RentalHome.search_board_sub(search_text)){ %>
							<TR class="selectableItem" onclick="document.location='./BoardView.jsp?aid=<%=b.get게시글번호()%>'">

			<TD><p align=center><%=b.get게시글번호()%></p></td>
			<td><p align=center><%=b.get말머리() %></p>
			</td>
			<td><p align=center>
			
			 <%= b.get이름() %>
			</p></td>
			<td><p align=center>
			<% for(Board bc : RentalHome.getCommentCount(b.get게시글번호())){%>
			<%=b.get제목()%>&nbsp;&nbsp;&nbsp;[<%=bc.get댓글수() %>]<%} %>
			
			</p></td>
			<Td><p align=center><%=b.get날짜()%></p>
			</td>
		</TR>
							
							
					<%	}
					}
					else if(search_select.equals("이름")){
						for(Board b : RentalHome.search_board_name(search_text)){ %>
							<TR class="selectableItem" onclick="document.location='./BoardView.jsp?aid=<%=b.get게시글번호()%>'">

			<TD><p align=center><%=b.get게시글번호()%></p></td>
			<td><p align=center><%=b.get말머리() %></p>
			</td>
			<td><p align=center>
			
			<%= b.get이름() %></p></td>
			<td><p align=center>
			
					<% for(Board bc : RentalHome.getCommentCount(b.get게시글번호())){%>
			<%=b.get제목()%>&nbsp;&nbsp;&nbsp;[<%=bc.get댓글수() %>]<%} %>
			
			</p></td>
			<Td><p align=center><%=b.get날짜()%></p>
			</td>
		</TR>
							
							
							
					<%	}
					}
				}
			}

		else {
			//for (Board b : RentalHome.BoardList()){
				 for (Board b : RentalHome.selectPage(currentPage, pageSize)) { %>

		
		<TR class="selectableItem" onclick="document.location='./BoardView.jsp?aid=<%=b.get게시글번호()%>'">

			<TD><p align=center><%=b.get게시글번호()%></p></td>
			<td><p align=center><%=b.get말머리() %></p>
			</td>
			<td><p align=center>
			
			<%= b.get이름() %></p></td>
			<td><p align=center>
						<% for(Board bc : RentalHome.getCommentCount(b.get게시글번호())){%>
			<%=b.get제목()%>&nbsp;&nbsp;&nbsp;[<%=bc.get댓글수() %>]<%} %>
			
			</p></td>
			<Td><p align=center><%=b.get날짜()%></p>
			</td>
		</TR>
		<%
			} } 
			//}
		%>
	</table>
		</form>
		
	<p align="center">	<my:pager2 pageSize="<%= pageSize %>" recordCount="<%= RentalHome.selectCount() %>" /></p>
		
		
		
		<% 
%>
<table width="100%"><tr><td align="center">
<p align="center">
<form method="post">
<select name="search_select">
			<OPTION VALUE="제목">제목</OPTION>
			<OPTION VALUE="이름">이름</option>
		</SELECT>
		<input type="text" name="search_text">
		<input name="cmd" type="submit" class="btn btn-inverse" value="검색"></p>
		<p align="right">

		</form>
			</p>
</td></tr></table>

	</TD>
</TR>

<TR HEIGHT="100">
<TD><%@ include file="./bottom.jsp"%></TD> 
</TR>
</TABLE>
</body>
</html>